<template>
    <div class="shopcar-container">
        <div class="goods-list">
            <div class="mui-card" v-for="(item, i) in goodsList" :key="item.id">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<mt-switch v-model="$store.getters.getGoodsSelected[item.id]" @change="selectedChanged(item.id,$store.getters.getGoodsSelected[item.id])"></mt-switch>
                        <img :src="item.thumb_path" alt="">
                        <div class="info">
                            <h1>{{item.title}}</h1>
                            <p>
                                <span class="price">¥{{item.sell_price}}</span>
                                <numbox :initcount="$store.getters.getGoodsCount[item.id]" :goodsid="item.id"></numbox>
                                <a href="#" @click.prevent="remove(item.id, i)">删除</a>
                            </p>
                        </div>
					</div>
				</div>
			</div>

            <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
						<div class="left">
                            <p>总计(不含运费)</p>
                            <p>已勾选商品 <span class="red">{{$store.getters.getGoodsCountAndAmount.count}}</span> 件,总价 <span class="red">¥{{$store.getters.getGoodsCountAndAmount.amount}}</span></p>
                        </div>
                        <mt-button type="danger">去结算</mt-button>
					</div>
				</div>
			</div>

            <p>{{ $store.getters.getGoodsSelected }}</p>
        </div>
    </div>
</template>

<script>
import numbox from '../subcomponents/shopcar_numbox.vue'
export default{
    data() {
        return {
            goodsList:[
                {cou:1,id:87,sell_price:2195,thumb_path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa0.att.hudong.com%2F52%2F62%2F31300542679117141195629117826.jpg&refer=http%3A%2F%2Fa0.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1616143166&t=53bfed8379d8ab65334b68c04072df8d',title:'华为荣耀'},
                {cou:2,id:89,sell_price:2199,thumb_path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa4.att.hudong.com%2F63%2F70%2F06300000046969120433706514748.jpg&refer=http%3A%2F%2Fa4.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1616143166&t=f32a3fb1bf7b11a03b43bc7b7dab48a4',title:'小米手机'},
                {cou:2,id:90,sell_price:4799,thumb_path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa3.att.hudong.com%2F57%2F48%2F01300000164151121967488746888.jpg&refer=http%3A%2F%2Fa3.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1616143166&t=5cdb79a46a7d75eacae8e6ef2b56b1fc',title:'三星手机'},
                {cou:5,id:91,sell_price:6500,thumb_path:'https://ss3.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/42166d224f4a20a4b44741a690529822720ed072.jpg',title:'苹果手机'}
            ]
        }
    },
    methods:{
        getGoodsList(){
            var idArr = [];
            this.$store.state.car.forEach(item => {
              idArr.push(item.id);
            });

            if(idArr.length<=0){
              return;
            }
        },
        remove(id,index){
            this.goodsList.splice(index,1);
            this.$store.commit("removeFromCar",id);
        },
        selectedChanged(id, val){
          console.log(id +'-----'+ val)
          this.$store.commit("updateGoodsSelected",{id, selected: val})
        }
    },
    components:{
        numbox
    }
}
</script>

<style lang="scss" scoped>
.shopcar-container{
    background-color: #eee;
    overflow: hidden;
    .goods-list{
        .mui-card-content-inner{
            display: flex;
            align-items: center;
        }
        img{
            width: 60px;
            height: 60px;
        }
        h1{
            font-size: 13px;

        }
        .info{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .price{
                color: red;
                font-weight: bold;
            }
        }
    }
    .jiesuan{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .red{
            color: red;
            font-weight: bold;
            font-size: 15px;
        }
    }
}
</style>